<?php

namespace App\Services;

use App\Caches\Account as AccountCache;
use App\Models\Account as AccountModel;
use App\Repos\Account as AccountRepo;

class Account extends Service
{
    protected $useCache = true;

    public function useCache($useCache = true): Account
    {
        $this->useCache = $useCache;
        return $this;
    }

    public function get($id): ?AccountModel
    {
        if ($this->useCache) {
            $cache = new AccountCache();
            return $cache->get($id);
        } else {
            $repo = new AccountRepo();
            return $repo->findById($id);
        }
    }
}